C#: Data flow for positional patterns. - #22689
Conversation
84d670d to
f059beb
Compare
f059beb to
f3eaab2
Compare
…rns into the readStepPattern predicate.
f3eaab2 to
ae1c4ad
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Nested positional patterns that capture the whole inner tuple still lose flow to the capture variable.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds tuple-backed positional-pattern support to C# data-flow analysis, including nested patterns.
Changes:
- Models flow through positional patterns in
isexpressions andswitchcases. - Adds nested-pattern tests and updates generated expectations.
- Documents the analysis improvement.
| File | Description |
|---|---|
| csharp/ql/test/library-tests/dataflow/tuples/Tuples.expected | Updates expected flow results. |
| csharp/ql/test/library-tests/dataflow/tuples/Tuples.cs | Adds nested positional-pattern tests. |
| csharp/ql/test/library-tests/dataflow/tuples/PrintAst.expected | Updates expected test syntax trees. |
| csharp/ql/test/library-tests/dataflow/tuples/DataFlowStep.expected | Updates expected flow steps. |
| csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll | Adds positional-pattern flow modeling. |
| csharp/ql/lib/change-notes/2026-10-02-positional-pattern-flow.md | Documents the new support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
hvitved
left a comment
There was a problem hiding this comment.
LGTM, but did you consider modeling this as calls to Deconstruct? Then we would have to define MaD models for tuple deconstruct methods.
No, I must admit, that I didn't consider it. Deconstruction also applies for other cases (like |

In this PR we add data flow support via positional patterns. That is,
Note, that positional patterns are similar to tuple patterns (
var (x, y)), but they haven't been handled in the data flow library before now.DCA looks good.